package com.dcjt.firehotcarpad.adapter

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.DialogInterface
import android.graphics.Color
import com.allen.library.SuperTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.dcjt.firehotcarpad.R
import com.dcjt.firehotcarpad.entity.CarDetailEntity
import com.dcjt.firehotcarpad.utils.AlertViewUtil
import com.dcjt.firehotcarpad.utils.StringUtils

/**
 * 车辆绑定
 */
class CarConfigAdapter(context: Activity, data: List<CarDetailEntity>?)
    : BaseQuickAdapter<CarDetailEntity, BaseViewHolder>(R.layout.item_car_config, data) {
    private var currentView: SuperTextView? = null
    private var onClickLisenter: OnClickLisenter? = null


    @SuppressLint("ResourceAsColor")
    override fun convert(helper: BaseViewHolder?, item: CarDetailEntity?) {


        if (item != null) {

            item?.let {

                helper?.getView<SuperTextView>(R.id.stv_detail)!!.isEnabled = !StringUtils.isEmpty(it.account)
                helper?.getView<SuperTextView>(R.id.stv_detail)!!.setCenterTopString(it.clmc)!!
                    .setCenterString(it.cljc+ if (StringUtils.isEmpty(it.account) ) "(无权限)" else "(正常)")!!.setCenterBottomString(it.cphm )

                if (StringUtils.isEmpty(it.account) ){
                    helper?.getView<SuperTextView>(R.id.stv_detail).setBackgroundResource(R.color.text_aaa)
                } else{
                    helper?.getView<SuperTextView>(R.id.stv_detail).setBackgroundResource(R.color.white)
                }

                helper?.getView<SuperTextView>(R.id.stv_detail).setOnSuperTextViewClickListener {
                    if (currentView != null) {
                        if (currentView!= it){
                            currentView?.setBackgroundResource(R.color.white)
                            it?.setBackgroundResource(R.color.mainColor)
                        }
                    } else{
                        it?.setBackgroundResource(R.color.mainColor)
                        currentView = it
                    }
                    if (onClickLisenter != null){
                        onClickLisenter?.setOnclick(item)
                    }
                }
            }
        }
    }
    public fun setOnClick( onClick:OnClickLisenter ) {
        this.onClickLisenter = onClick
    }

}

interface OnClickLisenter{
    fun setOnclick(detail:CarDetailEntity)
}
